<?php
/**
 * User: junely
 * Date: 2016/9/28
 * Time: 19:19
 * 用户: 市场临时专用
 */
namespace Home\Controller;


use Common\Library\BusinessException;
use Common\Library\Constant;
use Common\Library\Http\Request;
use Common\Library\Http\Response;
use Common\Library\SendSMS;
use Home\Model\ConsumeHistoryModel;
use Home\Model\CreditVettingModel;
use Home\Model\FinishModel;
use Think\Controller;
use Think\Log;

class MarketController extends Controller
{
    public function __construct()
    {
        parent::__construct();

        try {
            Request::parse();
        } catch (BusinessException $e) {
            $this->ajaxReturn(['code' => $e->getCode(), 'msg' => $e->getMessage()]);
        }
    }

    /****** 登陆 ******/
    public function SignIn()
    {
        try{
            //参数校验
            $user_id = I('post.user_id', 0, 'int');
            $mobile = I('post.mobile', '', 'string');
            $password = I('post.password', '', 'string');
            if(!$user_id && (!$mobile || !$password)){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            if($user_id){
                $data = ['id'=>$user_id, 'user_status'=>1];
            }else{
                //手机号格式校验
                if(!is_mobile($mobile)){
                    BusinessException::throwException(Constant::INVALID_MOBILE);
                }
                $data = ['mobile'=>$mobile, 'user_status'=>1];
            }


            //用户是否存在
            $user = M('AdminUsers')->where($data)->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }

            //密码校验
            if(!$user_id && !sp_compare_password($password, $user['user_pass'])){
                BusinessException::throwException(Constant::PASSWORD_NOT_MATCH);
            }
            
            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data']['user_id'] = $user['id'];
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 登陆 ******/
    public function UpdPWD()
    {
        try{
            //参数校验
            $admin_id = I('post.admin_id', 0, 'int');
            $password = I('post.password', '', 'string');
            $oldpass = I('post.oldpass', '', 'string');
            if(!$admin_id && !$password && !$oldpass){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            if($admin_id){
                $data = ['id'=>$admin_id, 'user_status'=>1];
            }

            //用户是否存在
            $user = M('AdminUsers')->where($data)->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }

            //旧密码校验
            if(!sp_compare_password($oldpass, $user['user_pass'])){
                BusinessException::throwException(Constant::OLD_PWD_ERR);
            }

            //密码加密
            $pwd_encode = sp_password($password);
            $upd_data = [
                'user_pass' => $pwd_encode,
                'id' => $admin_id
            ];
            $res = M('AdminUsers')->save($upd_data);

            $ret = Constant::getReturn(Constant::SUCCESS);
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 获取待审核订单列表 ******/
    public function GetReviewList()
    {
        try{
            $length = I('post.length', 10, 'int');
            $offset = I('post.offset', 0, 'int');
            $admin_id = I('post.admin_id', 10, 'int');
            if(!$admin_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            //检验业务员是否存在
            $admin = M('AdminUsers')->where(['id'=>$admin_id, 'user_status'=>1])->find();
            if(!$admin){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }

            //根据业务员省份id获取对应的所有的county_id
            $county_id_str = 0;
            if($admin['provice_id']){
                $county_id_str = D('Position')->getAllCountyIdByProviceId($admin['provice_id']);
            }

            //获取该业务员对应的所有的待审核订单列表
            $res = D('ConsumeHistory')->getReviewList($offset, $length, $county_id_str);
            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['total'] = $res['total'];
            $ret['offset'] = $offset;
            $ret['length'] = $length;
            unset($res['total']);
            $ret['data'] = $res;
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /******根据业务员id获取业务员信息 ******/
    public function GetAdminInfo()
    {
        try{
            //参数校验
            $user_id = I('post.admin_id', 0, 'int');
            if(!$user_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $data = ['1'=>1];
            if($user_id){
                $data = ['id'=>$user_id, 'user_status'=>1];
            }


            //用户是否存在
            $user = M('AdminUsers')->field('user_login AS name, mobile')->where($data)->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }

            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data'] = $user;
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 根据用户id获取用户可担保的订单信息 ******/
    public function GetAssureWithdrawalByCID()
    {
        try{
            $customer_id = I('post.customer_id', 0, 'int');
            $product_id = I('post.product_id', 0, 'int');
            if(!$customer_id || !$product_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            D('Customer')->has($customer_id);

            $res_data = [];
            $res = M('ConsumeHistory')->where(['customer_id'=>$customer_id, 'type'=>['in', "1, ".$product_id]])
                ->order('id desc')->find();
            if($res){
                //获取配置的还款月数
                $repay_conf = M('SysInstallmentPlan')->where(['id'=>$res['repay_id']])->find();
                if($repay_conf){
                    $res_data['repay_times'] = $repay_conf['repay_times'];
                }
                //获取失败的原因
                $res_data['button_text'] = '无法担保';
                $res_data['is_clicked'] = true;
                $reason = M('DecisionEngineLog')->where(['consume_id'=>$res['id'], 'customer_id'=>$customer_id])->find();
                Log::write("sql=".M('DecisionEngineLog')->getLastSql(), Log::DEBUG);
                if($reason){
                    if($res['status'] == ConsumeHistoryModel::STATUS_REVIEW_FAILED && $reason['status'] == 1
                        || $res['status'] == ConsumeHistoryModel::STATUS_TONDDUN_FAILED){
                        $res_data['button_text'] = '立即担保';
                        $res_data['is_clicked'] = false;
                    }else if($res['status'] == ConsumeHistoryModel::STATUS_REVIEW_FAILED && $reason['code'] == Constant::INVALID_LOCAL){
                        $res_data['button_text'] = '金主非本地人';
                        $res_data['is_clicked'] = true;
                    }else if($res['status'] == ConsumeHistoryModel::STATUS_CANCEL){
                        $res_data['button_text'] = '金主已取消订单';
                        $res_data['is_clicked'] = true;
                    }else if($res['status'] == ConsumeHistoryModel::STATUS_DOWN_PAYMENT || $res['status'] == ConsumeHistoryModel::STATUS_WAITING_REPAY){
                        $res_data['button_text'] = '金主订单已审核';
                        $res_data['is_clicked'] = true;
                    }else if($res['status'] == ConsumeHistoryModel::STATUS_WAIT_REVIEWED || $res['status'] == ConsumeHistoryModel::STATUS_WAIT_TWO){
                        $res_data['button_text'] = '金主订单待审核';
                        $res_data['is_clicked']= true;
                    }else{
                        $res_data['button_text'] = '金主订单已完成';
                        $res_data['is_clicked'] = true;
                    }
                }
                $res_data['amount'] = $res['amount'];
                $res_data['consume_id'] = $res['id'];
                $res_data['status'] = $res['status'];
                $res_data['type'] = $res['type'];
                $res_data['add_time'] = date('Y-m-d H:i:s', $res['add_time']);
            }else{
                $res_data = [];
            }

            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data'] = $res_data;
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 获取待审核订单列表 ******/
    public function GetWithdrawalByCID()
    {
        try{
            $customer_id = I('post.customer_id', 0, 'int');
            if(!$customer_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            D('Customer')->has($customer_id);

            $res = M('ConsumeHistory')->where(['customer_id'=>$customer_id, 'type'=>Constant::PAY_TYPE_WITHDRAWAL_APPLY])
                ->order('id desc')->find();
            if($res){
                if($res['status'] != ConsumeHistoryModel::STATUS_WAIT_REVIEWED){
                    $res_data['status'] = 1;
                }else{
                    $res_data['status'] = 0;
                }
                $repay_conf = M('SysInstallmentPlan')->where(['id'=>$res['repay_id']])->find();
                $res_data['amount'] = $res['consume_amount'];
                $res_data['consume_id'] = $res['id'];
                $res_data['add_time'] = date('Y-m-d H:i:s', $res['add_time']);
                $res_data['repay_times'] = $repay_conf['repay_times'];
            }else{
                $res_data = [];
            }

            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data'] = $res_data;
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 订单审核  ******/
    public function OrderReview(){
        try{
            //参数校验
            $goods_name = I('post.goods_name', '', 'string');
            $consume_id = I('post.consume_id', 0, 'int');
            $user_id = I('post.user_id', 0, 'int');
            $review_option = I('post.review_option', 0, 'int');
            $discount = I('post.discount', false, 'boolean');
            if(!$consume_id || !$user_id || !$goods_name){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            //业务员校验
            $user = M('AdminUsers')->where(['id'=>$user_id, 'user_status'=>1])->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }
            //订单校验
            $order=D("ConsumeHistory")->where(['id'=>$consume_id])->find();
            if(!$order){
                BusinessException::throwException(Constant::ORDER_ID_NOT_FOUNT);
            }

            //根据订单county_id获取对应的省份id
            if($order['county_id']){
                $provice_id = D('Position')->getProvinceIDByCountyID($order['county_id']);
                Log::write("provice_id=".json_encode($provice_id), Log::DEBUG);
                if($provice_id['province_id'] != $user['provice_id']){
                    BusinessException::throwException(Constant::ADMIN_NO_PERMISSION);
                }
            }else{
                BusinessException::throwException(Constant::ADMIN_NO_PERMISSION);
            }
            $res=D("ConsumeHistory")->field("status, customer_id, type")->where(['id'=>$consume_id])->find();
            if($res['status'] != ConsumeHistoryModel::STATUS_WAIT_REVIEWED && $res['status'] != ConsumeHistoryModel::STATUS_REVIEW_CANCEL){
                BusinessException::throwException(Constant::ORDER_ID_STATUS_ERROR);
            }
            //修改订单状态
            if($review_option == CreditVettingModel::STATUS_MARKET_REFUSE){
                $upd_data = [
                    'status' => ConsumeHistoryModel::STATUS_REVIEW_FAILED,
                    'goods_name' => $goods_name
                ];
                if(!(M("ConsumeHistory")->where(['id'=>$consume_id])->setField($upd_data))){
                    BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
                }
            }else{
                if($discount){
                    $data["discount_interest"] = FinishModel::SYSTEM_DISCOUNT;
                    //优惠规则：每月每人只能优惠4次
                    $already_count = D('CreditVetting')->getDiscountCountByOpr($user_id);
                    if($already_count >= 4){
                        BusinessException::throwException(Constant::ADMIN_NO_DISCOUNT);
                    }
                }
                $data['status'] = ConsumeHistoryModel::STATUS_WAIT_TWO;
                $data['goods_name'] = $goods_name;
                if(!(D("ConsumeHistory")->where(['id'=>$consume_id])->setField($data))){
                    BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
                }
            }
            //保存信审表日志
            $data['customer_id']=$res['customer_id'];
            $data['consume_id']=$consume_id;
            $data['type']=$res['type'];
            $data['opr_id']=$user_id;
            $data['status']=$review_option;
            $data['valuation']=0;
            $data['add_time']=date("Y-m-d H:i:s",time());
            if(!($ins = D("CreditVetting")->add($data))){
                Log::write("市场审核: sql=".M('CreditVetting')->getLastSql(), Log::DEBUG);
                BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
            }

            $pushId = M('Customer')->where(['id'=>$res['customer_id']])->getField('push_id');
            if($pushId){
                $data['consume_id'] = $consume_id;
                $msgContent = "亲，订单有新进度咯！";
                D('JPush')->send_push($data, 5, $pushId, $msgContent);
            }

            $ret = Constant::getReturn(Constant::SUCCESS);
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 订单审核复审  ******/
    public function OrderReviewTwo(){
        try{
            //参数校验
            $goods_imei = I('post.goods_imei', '', 'string');
            $consume_id = I('post.consume_id', 0, 'int');
            $user_id = I('post.user_id', 0, 'int');
            if(!$consume_id || !$user_id || !$goods_imei){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            //业务员校验
            $user = M('AdminUsers')->where(['id'=>$user_id, 'user_status'=>1])->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }
            //订单校验
            $order=D("ConsumeHistory")->where(['id'=>$consume_id])->find();
            if(!$order){
                BusinessException::throwException(Constant::ORDER_ID_NOT_FOUNT);
            }
            //订单状态检查
            if($order['status'] != ConsumeHistoryModel::STATUS_SEND_GOODS && $order['status'] != ConsumeHistoryModel::STATUS_SEND_MONEY_FAILED){
                BusinessException::throwException(Constant::ORDER_ID_STATUS_ERROR);
            }

            //修改订单状态
            $upd_data = [
                'status' => ConsumeHistoryModel::STATUS_SEND_MONEY_WAITING,
                'goods_imei' => $goods_imei
            ];
            if(!(M("ConsumeHistory")->where(['id'=>$consume_id])->setField($upd_data))){
                BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
            }

            //保存信审表日志
            $data['customer_id']=$order['customer_id'];
            $data['consume_id']=$consume_id;
            $data['type']=$order['type'];
            $data['opr_id']=$user_id;
            $data['status']=13;
            $data['valuation']=0;
            $data['reason']='客户相关的发货照片已上传';
            $data['add_time']=date("Y-m-d H:i:s",time());
            if(!($ins = D("CreditVetting")->add($data))){
                Log::write("市场审核: sql=".M('CreditVetting')->getLastSql(), Log::DEBUG);
                BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
            }

            $pushId = M('Customer')->where(['id'=>$order['customer_id']])->getField('push_id');
            if($pushId){
                $data['consume_id'] = $consume_id;
                $msgContent = "亲，订单有新进度咯！";
                D('JPush')->send_push($data, 5, $pushId, $msgContent);
            }

            $ret = Constant::getReturn(Constant::SUCCESS);
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 订单担保  ******/
    public function OrderAssure(){
        try{
            //参数校验
            $consume_id = I('post.consume_id', 0, 'int');
            $status = I('post.status', 0, 'int');
            $type = I('post.type', 0, 'int');
            $user_id = I('post.user_id', 0, 'int');
            if(!$consume_id || !$user_id || !$status || !$type){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            //业务员校验
            $user = M('AdminUsers')->where(['id'=>$user_id, 'user_status'=>1])->find();
            if(!$user){
                BusinessException::throwException(Constant::USER_NOT_FOUNT);
            }
            //担保数量限制：每月每人1次
            $already_count = M('CreditVetting')->where(['opr_id'=>$user_id, 'status'=>9, 'left(add_time, 7)'=>date('Y-m', time())])->count();
            if($already_count >= 1){
                BusinessException::throwException(Constant::ADMIN_NO_ASSURE);
            }
            //订单校验
            $order=D("ConsumeHistory")->where(['id'=>$consume_id, 'type'=>$type, 'status'=>$status])->find();
            if(!$order){
                BusinessException::throwException(Constant::ORDER_ID_NOT_FOUNT);
            }

            //根据订单county_id获取对应的省份id
            if($order['county_id']){
                $provice_id = D('Position')->getProvinceIDByCountyID($order['county_id']);
                if($provice_id['province_id'] != $user['provice_id']){
                    BusinessException::throwException(Constant::ADMIN_NO_PERMISSION);
                }
            }else{
                BusinessException::throwException(Constant::ADMIN_NO_PERMISSION);
            }

            //修改订单状态
            if(!(D("ConsumeHistory")->where(['id'=>$consume_id])->setField("status", ConsumeHistoryModel::STATUS_WAIT_TWO))){
                BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
            }
            //保存信审表日志
            $data['customer_id']=$order['customer_id'];
            $data['consume_id']=$consume_id;
            $data['type']=$order['type'];
            $data['opr_id']=$user_id;
            $data['status']=CreditVettingModel::STATUS_MARKET_ASSURE;
            $data['valuation']=0;
            $data['reason']='业务员担保';
            $data['add_time']=date("Y-m-d H:i:s",time());
            if(!($ins = D("CreditVetting")->add($data))){
                Log::write("市场审核: sql=".M('CreditVetting')->getLastSql(), Log::DEBUG);
                BusinessException::throwException(Constant::INTERNAL_ERROR_MYSQL);
            }
            $ret = Constant::getReturn(Constant::SUCCESS);
        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 市场端审核优惠信息 ******/
    public function getDiscountInfo()
    {
        try{
            //检查参数正确性
            $consume_id = I('post.consume_id', 0, 'int');
            if(!$consume_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            //获取订单分期配置信息
            $consume = M('ConsumeHistory')->where(['id'=>$consume_id])->find();
            $conf = M('SysInstallmentPlan')->where(['id'=>$consume['repay_id'], 'publish'=>1, 'target'=>1])->find();
            //Log::write("sql=".M('SysInstallmentPlan')->getLastSql().",配置信息：".json_encode($consume, JSON_UNESCAPED_UNICODE), Log::DEBUG);

            $discount_interest = $conf['discount_interest'];
            $new_conf['repay_times'] = $conf['repay_times'];
            $new_conf['interest_rate'] = $conf['interest_rate'];
            $new_conf['cut_interest'] = $conf['cut_interest'];

            //如果商户有优惠利息，则按商户优惠利息计算
            $merchant = M('MerchantInstallmentPlan')->where(['merchant_id'=>$consume['merchant_id'], 'repay_times'=>$conf['repay_times'], 'publish'=>1])->find();
            Log::write("商户优惠利息:".json_encode($merchant).",".$merchant['discount_interest'],Log::DEBUG);
            if($merchant){
                if($merchant['discount_interest']>0){
                    $discount_interest = $merchant['discount_interest'];
                }else{
                    //获取商户区域id
                    $county_id = M('Merchant')->where(['id'=>$consume['merchant_id']])->field('county_id')->find();
                    if(!$county_id){
                        BusinessException::throwException(Constant::MERCHANT_NOT_FOUND);
                    }
                    $province_id = D('Position')->getProvinceIDByCountyID($county_id['county_id']);
                    //首先判断当前产品是否为区域产品
                    if(!$conf['county_id']){
                        //如果有区域优惠利息，则按区域优惠利息计算，否则按全国规定优惠计算
                        $province_conf = M('SysInstallmentPlan')->where(['repay_times'=>$conf['repay_times'], 'county_id'=>$province_id['province_id']])->find();
                        if($province_conf && $province_conf['discount_interest']){
                            $discount_interest = $province_conf['discount_interest'];
                        }
                    }
                }
                $new_conf['interest_rate'] = $merchant['interest_rate'];
            }else{
                //获取商户区域id
                $county_id = M('Merchant')->where(['id'=>$consume['merchant_id']])->field('county_id')->find();
                if(!$county_id){
                    BusinessException::throwException(Constant::MERCHANT_NOT_FOUND);
                }
                $province_id = D('Position')->getProvinceIDByCountyID($county_id['county_id']);
                //首先判断当前产品是否为区域产品
                if(!$conf['county_id']){
                    //如果有区域优惠利息，则按区域优惠利息计算，否则按全国规定优惠计算
                    $province_conf = M('SysInstallmentPlan')->where(['repay_times'=>$conf['repay_times'], 'county_id'=>$province_id['province_id']])->find();
                    if($province_conf && $province_conf['discount_interest']){
                        $discount_interest = $province_conf['discount_interest'];
                        $new_conf['interest_rate'] = $province_conf['interest_rate'];
                    }
                }
            }

            //利率选择
            $ret = Constant::getReturn(Constant::SUCCESS);
            //计算正常分期金额和优惠分期金额
            if($conf['discount_interest']>0){
                //正常分期金额
                $res = D('Finish')->getWithdrawalDetail($consume['amount'], $new_conf);
                $ret['data']['orig'] = $res;
                //优惠分期金额
                $new_conf['interest_rate'] = $discount_interest;
                $discount = D('Finish')->getWithdrawalDetail($consume['amount'], $new_conf);
                $ret['data']['discount'] = $discount;
                //优惠总额
                $ret['discount_amount'] = ceil(($res['bill'] - $discount['bill'])*$conf['repay_times']);
            }else{
                $ret['discount_amount'] = 0;
            }

        }catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 获取业务员的30天内的订单 ******/
    public function GetClerkOrder()
    {
        try{
            //检查参数正确性
            $length = I('post.length', 10, 'int');
            $offset = I('post.offset', 0, 'int');
            $admin_id = I('post.admin_id', 0, 'int');

            if(!$admin_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            //获取业务员30天内的订单
            $res = D('ConsumeHistory')->getClerkOrder($admin_id, Constant::ORDER_DAYS, $offset, $length);
            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data'] = $res['res'];
            $ret['offset'] = $offset;
            $ret['length'] = $length;
            $ret['total'] = $res['total'];

        } catch (BusinessException $e) {
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /****** 获取 ******/
    public function GetUploadType()
    {
        try{
            //检查参数正确性
            $consume_id = I('post.consume_id', 0, 'int');

            if(!$consume_id){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            //获取上传类型
            $res = D('ConsumeHistory')->getUploadType($consume_id);
            $ret = Constant::getReturn(Constant::SUCCESS);
            $ret['data'] = $res;

        } catch (BusinessException $e) {
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }
}